package SentimentAnalysis;

import java.util.*;

import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.neural.rnn.RNNCoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.sentiment.SentimentCoreAnnotations;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.util.CoreMap;


public class Sentiment {
	
	public double sentiment(String text) {
		Annotation document = new Annotation(text);
		Properties props = new Properties();
		String sentiment = "";
	    props.setProperty("annotators", "tokenize, ssplit, parse, sentiment");
	    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
	    pipeline.annotate(document);
		String[] sentimentText = {"Very Negative", "Negative", "Neutral", "Positive", "Very Positive"};
		for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
			Tree tree = sentence.get(SentimentCoreAnnotations.AnnotatedTree.class);
			int score = RNNCoreAnnotations.getPredictedClass(tree);
			sentiment = sentimentText[score];
		}
		switch (sentiment) {
			case "Very Negative": return -1;
			
			case "Negative": return -0.5;
			
			case "Neutral": return 0;
			
			case "Positive": return 0.5;
			
			case "Very Positive": return 1;
			
			default: return -2;
		}
				
	}
}
